#include <stdio.h>
#include "linker_lists.h"

struct rectangle
{
	int width;
	int height;
};


/* global defination */
ll_entry_declare(struct rectangle, rect1, sharp) = {
	.width = 0x111,
	.height = 0x111,
};

ll_entry_declare(struct rectangle, rect2, sharp) = {
	.width = 0x222,
	.height = 0x222,
};

ll_entry_declare(struct rectangle, rect3, sharp) = {
	.width = 0x333,
	.height = 0x333,
};

int main()
{
	struct rectangle *rect1, *rect2, *start_ptr, *end_ptr;
	struct rectangle *rect_ptr;
	int count = 0, i = 0;

	/* 获取列表的开始和结束 */
	start_ptr = ll_entry_start(struct rectangle, sharp);
	end_ptr = ll_entry_end(struct rectangle, sharp);

	/* 获取列表中元素的个数 */
	count = ll_entry_count(struct rectangle, sharp);
	printf("count: %d\n", count);

	/* 获取单个元素的值 */
	rect1 = ll_entry_get(struct rectangle, rect1, sharp);
	printf("rect1 width: 0x%X\n", rect1->width);
	printf("rect1 height: 0x%X\n", rect1->height);
	
	/* 遍历列表 */
	rect_ptr = ll_entry_start(struct rectangle, sharp);
	count = ll_entry_count(struct rectangle, sharp);
	for (i = 0; i < count; i++) {
		printf("width: 0x%X\n", rect_ptr->width);
		printf("height: 0x%X\n", rect_ptr->height);
		printf("\n");

		++rect_ptr;
	}
	
	rect_ptr = ll_entry_start(struct rectangle, sharp);
	end_ptr = ll_entry_end(struct rectangle, sharp);
	while (rect_ptr != end_ptr) {
		printf("width: 0x%X\n", rect_ptr->width);
		printf("height: 0x%X\n", rect_ptr->height);
		printf("\n");

		++rect_ptr;
	}

	return 0;
}
